import pymysql


# 连接数据库
conn = pymysql.connect(host='localhost',
user='root',
password='root',
db='v3u',
charset='utf8')
# 创建一个游标
cursor = conn.cursor()

mylist = []

sql = "select a.count,b.name,b.id from(select count(1) as count,tag_id from links GROUP BY tag_id order by count desc) a left join tags b on a.tag_id = b.id where a.count > 1"
cursor.execute(sql)
datalist = cursor.fetchall()

for val in datalist:
    mylist.append([val[1],val[0],val[2]])

print(mylist)


